<template>
  <div class="app-container v-flex">
    <div>
      <div class="filter-container">
        <el-form
          ref="form"
          class="query-condition"
          @submit.native.prevent>
          <el-form-item>
            <el-select
              v-model="listQuery.platformId"
              placeholder="所属应用"
              style="width: 200px">
              <el-option
                v-for="item in platformOptions"
                :key="item.id"
                :label="item.platformName"
                :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="listQuery.platformId"
              placeholder="等级"
              style="width: 200px">
              <el-option
                v-for="item in platformOptions"
                :key="item.id"
                :label="item.platformName"
                :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="listQuery.platformId"
              placeholder="类型"
              style="width: 200px">
              <el-option
                v-for="item in platformOptions"
                :key="item.id"
                :label="item.platformName"
                :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="value1"
              class="filter-item-range"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期" />
          </el-form-item>
          <el-button
            class="filter-item icon-query"
            style="margin-left: 20px;"
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="search">
            查询
          </el-button>
          <el-button
            class="filter-item icon-red"
            size="mini"
            type="success"
            icon="el-icon-delete"
            @click="deleteAll">
            删除
          </el-button>
        </el-form>
      </div>
    </div>
    <div ref="main" class="v-flex-elastic">
      <el-table
        v-if="height>0"
        ref="multipleTable"
        v-loading="listLoading"
        :data="tableData"
        border
        :height="height"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          align="center"
          type="selection"
          width="40" />
        <el-table-column
          prop="appName"
          show-overflow-tooltip
          label="应用名称" />
        <el-table-column
          prop="appCode"
          show-overflow-tooltip
          label="日志等级" />
        <el-table-column
          prop="appVersion"
          show-overflow-tooltip
          label="日志类型" />
        <el-table-column
          prop="url"
          show-overflow-tooltip
          label="日志时间" />
        <el-table-column
          prop="desc"
          show-overflow-tooltip
          label="日志内容" />
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          width="60"
          class-name="small-padding fixed-width">
          <template slot-scope="{row ,$index}">
            <el-button
              v-permission-button="'ITPS-DELETE'"
              class="el-icon-defined"
              size="mini"
              icon="el-icon-delete"
              @click="deleteData(row,$index)" />
          </template>
        </el-table-column>
      </el-table>
    </div>

  </div>
</template>

<script>
import { getList } from '@/api/dsc/system/platform'
import { getListPage, deleteById } from '@/api/dsc/system/application'
import { tableMixin } from '@/utils/public'
export default {
  name: 'DscLog',
  mixins: [tableMixin],
  data() {
    return {
      height: 0, // table高度
      tableData: [], // 表格数据
      listQuery: {// 搜索条件
        keyName: '',
        platformId: ''
      },
      value1: [],
      platformOptions: [], // 所属平台option
      total: 0,
      listLoading: false,
      multipleSelection: [] // 选择行的复选框
    }
  },
  created() {
    getList({}).then(response => {
      this.platformOptions = response.data
    })
    this.getListPage()
  },
  methods: {
    // 查询列表
    getListPage() {
      this.listLoading = true
      getListPage(this.listQuery).then(response => {
        this.tableData = response.data
        // this.total = response.data.total
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 0 * 1000)
      }).catch(() => {
        this.listLoading = false
      })
    },
    // 搜索
    search() {
      this.getListPage()
    },
    // 删除
    deleteData(row, $index) {
      this.confirmBox('确定删除?').then(() => {
        deleteById(row.id).then(response => {
          this.notifiySuccess('删除成功!')
          // this.tableData.splice($index, 1)
          // this.total--
          this.getListPage()
        })
      }).catch(() => {

      })
    },
    // 批量删除
    deleteAll(row, $index) {
      this.confirmBox('确定删除?').then(() => {
        this.notifiySuccess('删除成功!')
      }).catch(() => {

      })
    },
    // 选择行复选框
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    // 全选、反选
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>
<style lang="scss">
  .filter-item-range{
    .el-range-separator{
      line-height: 20px;
    }
  }
</style>
